<template>
	<view class="system">
		<!-- 头部提示 -->
		<text class="tishi">为向您提供更好的用户体验，闲鱼在特定场景可能需要向您申请以下手机系统权限。</text>
		<!-- 权限 -->
		<view class="item" v-for="item in database" :key="item.id">
			<view class="text">
				<text>{{item.title}}</text>
				<text>{{item.content}}</text>
			</view>
			<u-switch v-model="item.state" :activeValue="'1'" :inactiveValue="'0'" activeColor="rgb(39,209,213)" @change='change(item)'></u-switch>
		</view>
		<view class="item" style="height: 10vh;"></view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				database: []
			};
		},
		methods: {
			// uView支持的事件
			change(item) {
				this.$api.gutSystemState(item).then(res => {
					// console.log(item)
					if(res.code == 200) {
						this.getSystemData()
					}
				})
			},
			// 获取数据
			getSystemData() {
				this.$api.getSystem().then(res => {
					// console.log(res)
					if(res.code == 200) {
						this.database = res.data
					}
				})
			}
		},
		created() {
			this.getSystemData()
		}
	}
</script>

<style lang="scss">
	.system {
		width: 100vw;
		height: calc(100vh - 88upx);
		background: rgb(242, 243, 247);
		overflow: hidden;

		.tishi {
			display: block;
			font-size: 26upx;
			padding: 40upx;
			color: rgb(153, 153, 153);
		}

		.item {
			display: flex;
			align-items: center;
			justify-content: space-between;
			width: 100%;
			margin: 4upx 0 0;
			padding: 20upx 40upx;
			box-sizing: border-box;
			background: white;

			.text {
				display: flex;
				flex-direction: column;
				color: black;

				text:last-child {
					font-size: 26upx;
					margin: 16upx 0 0;
					color: rgb(153, 153, 153);
				}
			}
		}
	}
</style>
